home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / architecture / i386 / reg_help.h < prev    next >
C/C++ Source or Header  |  1992-05-15  |  2KB  |  84 lines

  1. /* Copyright (c) 1991 NeXT Computer, Inc.  All rights reserved.
  2.  *
  3.  *    File:    architecture/i386/reg_help.h
  4.  *    Author:    Mike DeMoney, NeXT Computer, Inc.
  5.  *      Modified for i386 by: Bruce Martin, NeXT Computer, Inc.
  6.  *
  7.  *    This header file defines cpp macros useful for defining
  8.  *    machine register and doing machine-level operations.
  9.  *
  10.  * HISTORY
  11.  * 10-Mar-92  Bruce Martin (bmartin@next.com)
  12.  *    Adapted to i386
  13.  * 23-Jan-91  Mike DeMoney (mike@next.com)
  14.  *    Created.
  15.  */
  16.  
  17. #ifndef    _ARCH_I386_REG_HELP_H_
  18. #define    _ARCH_I386_REG_HELP_H_
  19.  
  20. /* Bitfield definition aid */
  21. #define    BITS_WIDTH(msb, lsb)    ((msb)-(lsb)+1)
  22. #define    BIT_WIDTH(pos)        (1)    /* mostly to record the position */
  23.  
  24. /* Mask creation */
  25. #define    MKMASK(width, offset)    (((unsigned)-1)>>(32-(width))<<(offset))
  26. #define    BITSMASK(msb, lsb)    MKMASK(BITS_WIDTH(msb, lsb), lsb & 0x1f)
  27. #define    BITMASK(pos)        MKMASK(BIT_WIDTH(pos), pos & 0x1f)
  28.  
  29. /* Register addresses */
  30. #if    __ASSEMBLER__
  31. # define    REG_ADDR(type, addr)    (addr)
  32. #else    __ASSEMBLER__
  33. # define    REG_ADDR(type, addr)    (*(volatile type *)(addr))
  34. #endif    __ASSEMBLER__
  35.  
  36. /* Cast a register to be an unsigned */
  37. #define    CONTENTS(foo)    (*(unsigned *) &(foo))
  38.  
  39. /* Stack pointer must always be a multiple of 4 */
  40. #define    STACK_INCR    4
  41. #define    ROUND_FRAME(x)    ((((unsigned)(x)) + STACK_INCR - 1) & ~(STACK_INCR-1))
  42.  
  43. /* STRINGIFY -- perform all possible substitutions, then stringify */
  44. #define    __STR(x)    #x        /* just a helper macro */
  45. #define    STRINGIFY(x)    __STR(x)
  46.  
  47. /*
  48.  * REG_PAIR_DEF -- define a register pair
  49.  * Register pairs are appropriately aligned to allow access via
  50.  * ld.d and st.d.
  51.  *
  52.  * Usage:
  53.  *    struct foo {
  54.  *        REG_PAIR_DEF(
  55.  *            bar_t *,    barp,
  56.  *            afu_t,        afu
  57.  *        );
  58.  *    };
  59.  *
  60.  * Access to individual entries of the pair is via the REG_PAIR
  61.  * macro (below).
  62.  */
  63. #define    REG_PAIR_DEF(type0, name0, type1, name1)        \
  64.     struct {                        \
  65.         type0    name0 __attribute__(( aligned(8) ));    \
  66.         type1    name1;                    \
  67.     } name0##_##name1
  68.  
  69. /*
  70.  * REG_PAIR -- Macro to define names for accessing individual registers
  71.  * of register pairs.
  72.  *
  73.  * Usage:
  74.  *    arg0 is first element of pair
  75.  *    arg1 is second element of pair
  76.  *    arg2 is desired element of pair
  77.  * eg:
  78.  *    #define    foo_barp    REG_PAIR(barp, afu, afu)
  79.  */
  80. #define    REG_PAIR(name0, name1, the_name)            \
  81.     name0##_##name1.the_name
  82.  
  83. #endif    _ARCH_I386_REG_HELP_H_
  84.